package com.tuantuan.controller;

import java.util.HashMap;
import java.util.Map;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.tuantuan.dao.CommenDao;
import com.tuantuan.model.Courses;
import com.tuantuan.service.CommenService;
/**
 * 课程资料控制层
 * @author Administrator
 *
 */
/**
 * 课程资料控制层
 * @author Administrator
 *
 */
@Controller
public class CoursesController {
	@Resource(name="CourseDao")
	private CommenDao<Courses> courDao;
	
	@Resource(name="CourseService")
	private CommenService<Courses> courSer;
	
	/**
	 * 分页查询课程资料
	 * @param request
	 * @param response
	 * @param c
	 * @return
	 */
	@RequestMapping("/course/queryCourses.do")
	@ResponseBody
	public Map<String, Object> queryByPage(HttpServletRequest request,HttpServletResponse response,Courses c){
		Map<String, Object> map = new HashMap<String, Object>();
		Courses cc = this.courDao.queryByPage(c);
		map.put("page", c);
		return map;
	}
	
	/**
	 * 添加课程资料
	 * @param request
	 * @param t
	 * @return
	 */
	@RequestMapping("/course/addCourse.do")
	@ResponseBody
	public String queryByPage(HttpServletRequest request, Courses c){
		
		return this.courSer.addEntity(c);
	}
	
	/**
	 * 获取更新课程信息页面数据
	 * @param request
	 * @param coId
	 * @return
	 */
	@RequestMapping("/course/toUpdateCourse.do")
	public String toUpdateCourse(HttpServletRequest request, int coId){
		
		Courses c = new Courses();
		c.setCoId(coId);
		Courses cc = this.courDao.queryById(c);
		request.setAttribute("courses", cc);
		return "course/courseView";
	}
	/**
	 * 获取需要更新的课程资料
	 * @param request
	 * @param response
	 * @param c
	 * @return
	 */
	@RequestMapping("/course/updateCourse.do")
	@ResponseBody
	public String  updateStudent(HttpServletRequest request,HttpServletResponse response,Courses c){
		return this.courSer.updateEntity(c);
	}

	/**
	 * 课程资料删除
	 * @param request
	 * @param coId
	 * @param pageCounts
	 * @return
	 */
	@RequestMapping("/course/deleteCourse.do")
	public String deleteCourse(HttpServletRequest request,int coId,int pageCounts){
		String flag = this.courSer.deleteEntity(coId);
		request.setAttribute("flag", flag);
		request.setAttribute("pageCounts", pageCounts);
		return "course/course";
	}
	public CommenDao<Courses> getCourDao() {
		return courDao;
	}

	public void setCourDao(CommenDao<Courses> courDao) {
		this.courDao = courDao;
	}

	public CommenService<Courses> getCourSer() {
		return courSer;
	}

	public void setCourSer(CommenService<Courses> courSer) {
		this.courSer = courSer;
	}
	
	
	
	
	
	
	
	
}
